﻿CREATE PROCEDURE [acms].[ExceptionLog_GetAllBySiteId]
	@SiteId int, 
	@StartIndex int,
	@MaxRecords int,
	@TotalRecordsOut int output
AS
	Select * From
	(
		Select b.*, Row_Number() Over (Order by Created desc) as RowNumber
		FROM ExceptionLog_View b
		Where SiteId = @SiteId
	) as a
	where a.RowNumber between @StartIndex + 1 and @StartIndex + @MaxRecords
	
	select @TotalRecordsOut = Count(Id)
	FROM ExceptionLog_View b
	Where SiteId = @SiteId

RETURN 0;